home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / adasmall / test6.ada < prev   
Text File  |  1996-01-30  |  2KB  |  92 lines

  1. with SMALL_SP; use SMALL_SP;
  2. procedure TEST6 is
  3.  
  4.   -------------------------------------------------------------------------
  5.   -- This program demonstrates WHEN clauses on SmallAda v2.0 SELECT      --
  6.   -- alternatives.                                                       --
  7.   -------------------------------------------------------------------------
  8.  
  9.   task R is
  10.     entry E1;
  11.     entry E2;
  12.     entry E3;
  13.   end R;
  14.  
  15.   task A;
  16.   task B;
  17.   task C;
  18.  
  19.   task body R is
  20.     GUARD1 : boolean;
  21.     GUARD2 : boolean;
  22.     GUARD3 : boolean;
  23.     I      : integer;
  24.   begin
  25.     CURSORAT(3,1); Put("TESTING GUARDED SELECT ALTERNATIVES, TEST #");
  26.     I := 1;
  27.     loop
  28.       CURSORAT(3,45); Put(I);
  29.       if RANDOM(100) > 50 then GUARD1 := true; else GUARD1 := false; end if;
  30.       if RANDOM(100) > 50 then GUARD2 := true; else GUARD2 := false; end if;
  31.       if RANDOM(100) > 50 then GUARD3 := true; else GUARD3 := false; end if;
  32.       CURSORAT(5,1); Put("GUARD ON ACCEPT E1 ===> ");
  33.       if GUARD1 then
  34.         Put("TRUE                           ");
  35.       else
  36.         Put("FALSE                          ");
  37.       end if;
  38.       CURSORAT(7,1); Put("GUARD ON ACCEPT E2 ===> ");
  39.       if GUARD2 then
  40.         Put("TRUE                           ");
  41.       else
  42.         Put("FALSE                          ");
  43.       end if;
  44.       CURSORAT(9,1); Put("GUARD ON ACCEPT E3 ===> ");
  45.       if GUARD3 then
  46.         Put("TRUE                           ");
  47.       else
  48.         Put("FALSE                          ");
  49.       end if;
  50.  
  51.       select
  52.         when GUARD1 => accept E1; 
  53.         CURSORAT(5,31); Put("*** CALL ACCEPTED ***");
  54.       or
  55.         when GUARD2 => accept E2;
  56.         CURSORAT(7,31); Put("*** CALL ACCEPTED ***");
  57.       or
  58.         when GUARD3 => accept E3;
  59.         CURSORAT(9,31); Put("*** CALL ACCEPTED ***");
  60.       or
  61.         delay 1.0;
  62.       end select;
  63.       delay 2.0;
  64.       I := I + 1;
  65.     end loop;
  66.   end R;
  67.  
  68.   task body A is
  69.   begin
  70.     loop
  71.       R.E1;
  72.     end loop;
  73.   end A;
  74.  
  75.   task body B is
  76.   begin
  77.     loop
  78.       R.E2;
  79.     end loop;
  80.   end B;
  81.  
  82.   task body C is
  83.   begin
  84.     loop
  85.       R.E3;
  86.     end loop;
  87.   end C;
  88.  
  89. begin
  90.   null;
  91. end TEST6;
  92.